<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('已分配员工')" />
</head>
<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="role-form">
				    <input type="hidden" id="teaShopId" name="teaShopId" th:value="${teaShop.id}">
					<div class="select-list">
						<ul>
							<li>
								<label>职位：</label>
								<select name="position" th:with="type=${@dict.getType('employee_position')}">
									<option value="">所有</option>
									<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
								</select>
							</li>
							<li>
								<label>姓名：</label>
								<input type="text" name="name"/>
							</li>
							<li>
								<label>手机号：</label>
								<input type="text" name="phone"/>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
							    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>

	        <div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-success" onclick="selectEmployees()">
	                <i class="fa fa-plus"></i> 添加员工
	            </a>
				<a class="btn btn-danger multiple disabled" onclick="cancelAllocateEmployeesAll()">
		            <i class="fa fa-remove"></i> 批量取消员工
		        </a>
		        <a class="btn btn-warning" onclick="closeItem()">
		            <i class="fa fa-reply-all"></i> 关闭
		        </a>
	        </div>

	        <div class="col-sm-12 select-table table-striped">
			    <table id="bootstrap-table"></table>
			</div>
		</div>
	</div>
	<th:block th:include="include :: footer" />
	<script th:inline="javascript">
		var editFlag = [[${@permission.hasPermi('system:employee:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:employee:remove')}]];
        var positionDatas = [[${@dict.getType('employee_position')}]];
        var prefix = ctx + "system/shop";

        $(function() {
            var options = {
                url: prefix + "/allocateEmployees/allocatedList",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "茶店员工",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '员工编号',
                },
                {
                    field: 'position',
                    title: '职位',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(positionDatas, value);
                    }
                },
                {
                    field: 'name',
                    title: '姓名'
                },
                {
                    field: 'phone',
                    title: '手机号'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
		                actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="cancelAllocateEmployee(\'' + row.id + '\')"><i class="fa fa-remove"></i>取消分配</a> ');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
		/* 选择员工 */
		function selectEmployees() {
			var url = prefix + '/unAllocateEmployees/' + $("#teaShopId").val();
		    $.modal.open("选择员工", url);
		}

		/* 批量取消员工 */
		function cancelAllocateEmployeesAll() {
		    var rows = $.table.selectFirstColumns();
       		if (rows.length == 0) {
       			$.modal.alertWarning("请至少选择一条记录");
       			return;
       		}
       		$.modal.confirm("确认要取消已分配的" + rows.length + "位员工吗?", function() {
				var data = { "teaShopId": $("#teaShopId").val(), "employeeIds": rows.join() };
    			$.operate.submit(prefix + "/allocateEmployees/cancelAll", "post", "json", data);
    		});
		}

		/* 取消员工 */
		function cancelAllocateEmployee(employeeId) {
			$.modal.confirm("确认要取消该员工的分配吗？", function() {
				$.operate.post(prefix + "/allocateEmployees/cancel", { "teaShopId": $("#teaShopId").val(), "employeeId": employeeId });
		    })
		}
	</script>
</body>
</html>